package com.moguhoutai.biz;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import org.springframework.stereotype.Service;

import com.moguhoutai.dao.ResourceMapper;
import com.moguhoutai.model.Resources;
import com.moguhoutai.util.BusinessException;

@Service
public class ResourceBiz {
	@Resource
	private ResourceMapper reMapperdao;
	
    public void save(Resources resources)throws BusinessException{
    	try {
			Date now =new Date();
			resources.setCreateTime(now);
			resources.setUpdateTime(now);
    		reMapperdao.insert(resources);
		} catch (Exception e) {
			e.printStackTrace();
  			throw new BusinessException("E05B01");
		}
    	
    }
	
    public Resources findById(String resId)throws BusinessException{
    	try {
		      return reMapperdao.selectByPrimaryKey(resId);
		} catch (Exception e) {
			e.printStackTrace();
  			throw new BusinessException("E05B05");
		}
    	
    }
	
    public void delete(Resources resources) throws BusinessException {
		try {
			reMapperdao.deleteByPrimaryKey(resources.getResId());
		} catch (Exception e) {
			e.printStackTrace();
			throw new BusinessException("E03B02");
		}
	}
    
    
    
    public List<Resources> findAll() throws BusinessException {
		try {
			return reMapperdao.findAll();
		} catch (Exception e) {
			e.printStackTrace();
			throw new BusinessException("E02B04");
		}
	}
	public long findCount() throws BusinessException {
		try {
			return reMapperdao.findCount();
		} catch (Exception e) {
			e.printStackTrace();
			throw new BusinessException("E01B06");
		}
	}
    
	public void update(Resources resources) throws BusinessException {
		try {
			Date now = new Date();
			resources.setCreateTime(now);
			resources.setUpdateTime(now);
			reMapperdao.updateByPrimaryKeySelective(resources);
		} catch (Exception e) {
			e.printStackTrace();
			throw new BusinessException("E04B03");
		}
	}
    
}
